//自定义PaletteProvider
function CustomPaletteProvider(
	palette, create, elementFactory,
	spaceTool, lassoTool, handTool,
	globalConnect, translate) {

	this._palette = palette;
	this._create = create;
	this._elementFactory = elementFactory;
	this._spaceTool = spaceTool;
	this._lassoTool = lassoTool;
	this._handTool = handTool;
	this._globalConnect = globalConnect;
	this._translate = translate;

	palette.registerProvider(this);
}

CustomPaletteProvider.$inject = [
	'palette',
	'create',
	'elementFactory',
	'spaceTool',
	'lassoTool',
	'handTool',
	'globalConnect',
	'translate'
];


CustomPaletteProvider.prototype.getPaletteEntries = function (element) {

	var actions = {},
		create = this._create,
		elementFactory = this._elementFactory,
		spaceTool = this._spaceTool,
		lassoTool = this._lassoTool,
		handTool = this._handTool,
		globalConnect = this._globalConnect,
		translate = this._translate;

	function createAction(type, group, className, title, options) {

		function createListener(event) {
			var shape = elementFactory.createShape(Object.assign({
				type: type
			}, options));

			if (options) {
				shape.businessObject.di.isExpanded = options.isExpanded;
			}

			create.start(event, shape);
		}

		var shortType = type.replace(/^bpmn:/, '');

		return {
			group: group,
			className: className,
			title: title || translate('Create {type}', {
				type: shortType
			}),
			action: {
				dragstart: createListener,
				click: createListener
			}
		};
	}

	function createSubprocess(event) {
		var subProcess = elementFactory.createShape({
			type: 'bpmn:SubProcess',
			x: 0,
			y: 0,
			isExpanded: true
		});

		var startEvent = elementFactory.createShape({
			type: 'bpmn:StartEvent',
			x: 40,
			y: 82,
			parent: subProcess
		});

		create.start(event, [subProcess, startEvent], {
			hints: {
				autoSelect: [startEvent]
			}
		});
	}

	function createParticipant(event) {
		create.start(event, elementFactory.createParticipantShape());
	}

	Object.assign(actions, {
		'global-connect-tool': {
			group: 'tools',
			className: 'bpmn-icon-connection-multi',
			title: translate('Activate the global connect tool'),
			action: {
				click: function (event) {
					globalConnect.toggle(event);
				}
			}
		},
		'tool-separator': {
			group: 'tools',
			separator: true
		},
		'create.start-event': createAction(
			'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none',
			translate('StartEvent')
		),
		'create.intermediate-event': createAction(
			'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
			translate('Intermediate Throw Event')
		),
		'create.end-event': createAction(
			'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-terminate',
			translate('EndEvent')
		),
		'create.boundary-event': createAction(
			'bpmn:BoundaryEvent', 'event', 'bpmn-icon-end-event-none',
			translate('Intermediate/Boundary Event')
		),
		'create.exclusive-gateway': createAction(
			'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
			translate('Gateway')
		),
		'create.userTask': createAction(
			'bpmn:UserTask', 'activity', 'bpmn-icon-user-task',
			translate('User Task')
		),
		'create.task': createAction(
			'bpmn:Task', 'activity', 'bpmn-icon-task',
			translate('Task')
		),
		'create.manualTask': createAction(
			'bpmn:ManualTask', 'activity', 'bpmn-icon-manual-task',
			translate('Manual Task')
		),
		'create.serviceTask': createAction(
			'bpmn:ServiceTask', 'activity', 'bpmn-icon-service-task',
			translate('Service Task')
		),
		'create.subprocess-expanded': {
			group: 'activity',
			className: 'bpmn-icon-subprocess-expanded',
			title: translate('expanded SubProcess'),
			action: {
				dragstart: createSubprocess,
				click: createSubprocess
			}
		}
	});

	return actions;
};

function CustomContextPadProvider(
	config, injector, eventBus,
	contextPad, modeling, elementFactory,
	connect, create, popupMenu,
	canvas, rules, translate) {

	config = config || {};

	contextPad.registerProvider(this);

	this._contextPad = contextPad;

	this._modeling = modeling;

	this._elementFactory = elementFactory;
	this._connect = connect;
	this._create = create;
	this._popupMenu = popupMenu;
	this._canvas = canvas;
	this._rules = rules;
	this._translate = translate;

	if (config.autoPlace !== false) {
		this._autoPlace = injector.get('autoPlace', false);
	}

}

CustomContextPadProvider.prototype.getContextPadEntries = function (element) {
	var actions = {};
	return actions;
};